{#`haystack`会自动的在`templates`文件夹下寻找这个模板文件渲染，#}
{#并且会给这个模板文件传入`page`、`paginator`、`query`等参数。#}
{#其中`page`和`paginator`分别是`django`内置的`Page`类和`Paginator`类的对象#}
{% extends "blog/base.html" %}

{% block title %}搜索{% endblock %}
{% block content %}
      {% if query %}
    <h1>博客中包含 "{{ query }}"</h1>
    <h3>
      {% with page.object_list.count as total_results %}
          查询结果有 {{ total_results }} 条
      {% endwith %}
    </h3>
        {% for result in page.object_list %}
            {% with result.object as post %}
            <h4><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></h4>
            {{ post.body|truncatewords:5 }}
            {% endwith %}
        {% empty %}
            <p>您的查询没有结果</p>
        {% endfor %}
    <p><a href="{% url "blog:post_search" %}">重新搜索</a></p>
    {% endif %}
{% endblock %}


